home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / packdemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-08  |  1.8 KB  |  54 lines

  1. {
  2. GPC demo program for true packed records and arrays, even of
  3. variable size.
  4.  
  5. Copyright (C) 1999-2001 Free Software Foundation, Inc.
  6.  
  7. Author: Frank Heckenbach <frank@pascal.gnu.de>
  8.  
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation, version 2.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; see the file COPYING. If not, write to
  20. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22.  
  23. As a special exception, if you incorporate even large parts of the
  24. code of this demo program into another program with substantially
  25. different functionality, this does not cause the other program to
  26. be covered by the GNU General Public License. This exception does
  27. not however invalidate any other reasons why it might be covered
  28. by the GNU General Public License.
  29. }
  30.  
  31. program PackingDemo;
  32.  
  33. var
  34.   n : Integer;
  35.   r : packed record
  36.         Foo : Boolean;   { 1 bit  }
  37.         Bar : (No, Yes); { 1 bit  }
  38.         Baz : 0 .. 3;    { 2 bits }
  39.         Qux : -1 .. 0;   { 1 bit  }
  40.         Fred : 1 .. 7    { 3 bits }
  41.       end;
  42.  
  43. begin
  44.   Writeln ('The packed record r, consisting of a Boolean, an enumeration type and');
  45.   Writeln ('3 integer subranges occupies only ', SizeOf (r), ' byte in memory.');
  46.   Writeln;
  47.   repeat
  48.     Write ('Now the size of a packed array of Booleans. How many Booleans? ');
  49.     Readln (n)
  50.   until n > 0;
  51.   var a : packed array [1 .. n] of Boolean;
  52.   Writeln ('A packed array of ', n, ' Booleans occupies ', SizeOf (a), ' byte(s) in memory.')
  53. end.
  54.